<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/static/admin/jsp/include.jsp"%>

<script type="text/javascript">
	var grid;
	var index;
	
	var addFun = function($dialog, $grid, $pjq) {
		var dialog = parent.sy.modalDialog({
			title : '录入艺术家',
			width : 700,
			height : 600,
            url : sy.contextPath + '/go?path=user/artUserEdit',
			buttons : [ {
				text : '保存',
				handler : function() {
					dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
				}
			} ]
		});
	};
	
	var editFun = function($dialog, $grid, $pjq) {
		var rows = grid.datagrid('getSelections');
		if (rows.length != 1) {
			parent.$.messager.w('请选择一条记录进行编辑！');
			return;
		}
		var dialog = parent.sy.modalDialog({
			title : '修改资料',
			width : 600,
			height : 400,
			url : sy.contextPath + '/go?path=user/artUserEdit&id=' + rows[0].id,
			buttons : [ {
				text : '保存',
				handler : function() {
					dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
				}
			} ]
		});
	};
	
	var creditsFun = function() {
		var rows = grid.datagrid('getSelections');
		if (rows.length != 1) {
			parent.$.messager.w('请选择一条记录进行查看！');
			return;
		}
		var nickName = "";
		if (rows[0].nickName != null && rows[0].nickName != "") {
			nickName = rows[0].nickName;
		}
		var url = sy.contextPath + '/go.do?path=user/userCreditLogList&id=' + rows[0].id;
		var dialog = parent.sy.modalDialog({
			title : '积分日志——' + nickName,
			width:sy.width-150,
			height:sy.height-100,
			//width : 800,
		//	height : 620,
			url : url
		});
		index = dialog.selector.substring(12);
		console.log(dialog.selector.substring(12));
	};
	
	$(function() {
		grid = $('#grid').datagrid({
			url : sy.contextPath + '/user/list?user_state=1',
//            onLoadSuccess:function(data){
//               grid.datagrid('enableDnd');
//            },
//			onDrop:function () {
//				var data = grid.datagrid('getRows');
//				var arr = [];
//				for (var i = 0; i < data.length; i++){
//				    var mini = {
//				        id:data[i].id,
//						sortOrder:i+1
//					}
//					arr.push(mini);
//				}
//				console.log(arr);
//            },
            columns : [ [ {
                width : $(this).width() * 0.05,
                title : 'id',
                field : 'id',
                checkbox:true,
                align : 'center',
            },{
                width : $(this).width() * 0.05,
                title : 'id',
                field : 'idColums',
                align : 'center',
                formatter : function (v,r,i) {
                    return r.id
                }
            },{
                width : $(this).width() * 0.05,
                title : '姓名',
                field : 'userName',
                align : 'center',
			},{
                width : $(this).width() * 0.05,
                title : '头像',
                field : 'artImg',
                align : 'center',
                formatter: function(v, r, i) {
                    if(v){
                        return po.showImg(v,20,20)
					}
                }
            },{
                width : $(this).width() * 0.05,
                title : '参拍数量',
                field : 'pawnLogCnt',
                align : 'center',
			},{
                width : $(this).width() * 0.05,
                title : '有效订单数量',
                field : 'orderCnt',
                align : 'center',
			},{
                width : $(this).width() * 0.05,
                title : '等级',
                field : 'vipLs',
                align : 'center',
			},{
                width : $(this).width() * 0.08,
                title : '联系方式(默认账号)',
                field : 'artPhone',
                align : 'center',
                formatter: function(v, r, i) {
                    return UT.addTitle(v);
                }
            },{
                width : $(this).width() * 0.1,
                title : '邮箱',
                field : 'artEmail',
                align : 'center',
                formatter: function(v, r, i) {
                    return UT.addTitle(v);
                }
            },{
				width : $(this).width() * 0.1,
				title : '个人履历',
				field : 'artInfo',
				align : 'center',
				formatter : function(v, r, i) {

					    return '<a href="javascript:void(0);" onclick="checkArtInfo(\''+r.id+'\')" class="button button-info" title="查看个人履历">查看个人履历</a>';

				}
			},{
                width : $(this).width() * 0.1,
                title : '毕业学校',
                field : 'school',
                align : 'center',
                formatter : function(v, r, i) {
                    return UT.addTitle(v);
                }
            },{
                width : $(this).width() * 0.1,
                title : '工作单位',
                field : 'company',
                align : 'center',
                formatter : function(v, r, i) {
                    return UT.addTitle(v);
                }
            },{
				width : $(this).width() * 0.1,
				title : '审核是否通过',
				field : 'isVerify',
				align : 'center',
				formatter : function(value, row, index) {
					switch (value) {
					case 0:
					   return '未通过';
					case 1:
                        return '已通过';
					}
				}
			}, {
					width : $(this).width() * 0.08,
					title : '创建时间',
					field : 'createTime',
					align : 'center',
					formatter : function(v){
					    if(v){
					        return v.substr(0,10);
						}
					}
			}, {
				width : $(this).width() * 0.08,
				title : '操作',
				field : 'op',
				align : 'center',
				formatter : function(value, row, index) {

					    if(row.isVerify == 0){
                            return '<a href="javascript:void(0);" onclick="verify(1,\''+row.id+'\')" class="button button-warning" title="审核通过">审核通过</a>';
						}else if(row.isVerify == 1){
                            return '<a href="javascript:void(0);" onclick="verify(0,\''+row.id+'\')" class="button button-warning" title="审核不通过">审核不通过</a>';
						}
					}
			}
			] ]
		});
		

		$('#type').combobox({   
			onSelect: function(rec){   
				grid.datagrid('load',sy.serializeObject($('#searchForm')));
	        } 
		});
	});

    /**
	 * 认证
     * @param verify
     * @param id
     */
	function verify(verify, id) {
		if (verify == 1) {
				var data = {
					id : id,
                    isVerify : 1
				};
				SaveData(data);
		} else if (verify == 0) {
            var data = {
                id : id,
                isVerify :0
            };
            SaveData(data);
		}
	}

	function checkArtInfo (id){
        var dialog = parent.sy.modalDialog({
            title : '艺术家简介',
            width : 700,
            height : 600,
            url : sy.contextPath + '/go?path=user/artUserInfo&id='+id,
        });
	}

	function SaveData(data) {
		var url = sy.contextPath + '/user/save';
		$.post(url, data, function() {
			grid.datagrid('reload');
		}, 'json');
	}

    /**
     * 导出excel
     */
    function exportExcel(){
        var url = sy.contextPath + '/user/exportArtExcel';
        location.href=url;
    }

    //批量送积分
    function upLoadList(){
        var rows = grid.datagrid('getSelections');
        if (rows.length == 0) {
            parent.$.messager.w('请选择！');
            return;
        }
        for(var a in rows){
            if(rows[a].orderState < 3){
                return layer.msg("您选中的订单中有无效交易，请去查看");
            }
        }

        var ids = [];
        for ( var i = 0, l = rows.length; i < l; i++) {
            var r = rows[i];
            ids.push(r.id);
        }
        var id = ids.join(',');
        var url = sy.contextPath + '/go?path=/user/userAddCredit&ids=' + id;
        var dialog = parent.sy.modalDialog({
            title : '指定用户赠送积分',
            width : 500,
            height : 300,
            url : url,
            buttons : [ {
                text : '保存',
                handler : function() {
                    dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                }
            } ]
        });
//                $.post(sy.contextPath + '/order/updateLoadEth', {
//                    id : id
//                }, function(result) {
//
//                    rows.length = 0;//必须，否则有bug
//                    if(result.errorCode == -1){
//                        return layer.msg('保存失败,'+result.errorMsg);
//                    }
//                    grid.datagrid('reload');
//                }, 'json');
    }
</script>
</head>
<body>
	<div id="toolbar">
		<form id="searchForm">
		<div>
			艺术家姓名或者联系方式:<input style="border: 1px solid #e4e4e4;height: 30px" type="text" name="artKey" onkeyup="grid.datagrid('load',sy.serializeObject($('#searchForm')));" style="width: 150px" prompt="真实姓名/联系方式"/>
			<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa-search'" onclick="grid.datagrid('load',sy.serializeObject($('#searchForm')));">过滤</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa-search-minus'" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
			<a href="javascript:void(0);" onclick="exportExcel();" class="button button-red" title="导出excel">导出excel</a>
		</div>
		</form>
		<div class="tbbutton">

			<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa-plus-circle',plain:true" onclick="addFun();">添加</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa-pencil',plain:true" onclick="editFun();">修改</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa-address-card'" onclick="upLoadList()">批量加分</a>
			<%--<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fa-trash',plain:true" onclick="delFun();">删除</a>--%>

		</div>
	</div>
	<table id="grid" data-options="fit:true,border:false"></table>
</body>
</html>